package com.avit.tv.kui.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.core.graphics.drawable.DrawableCompat;

/**
 * 图标工具类
 * @author like
 * @date 2020/6/10
 */
public class Utils {

    /**
     * 给imageView 加载svg 并给svg上色
     * @param imageView
     * @param svgDrawable
     * @param color
     */
    public static void setSvgImageRes(ImageView imageView, Drawable svgDrawable , @ColorInt int color){
        Drawable mutate = DrawableCompat.wrap(svgDrawable).mutate();
        mutate.setFilterBitmap(true);
        DrawableCompat.setTint(mutate, color);
        imageView.setImageDrawable(mutate);
    }


    /**
     * dp转 px
     * @param context
     * @param dp
     * @return
     */
    public static float dip2px(Context context, float dp){
        float scale = context.getResources().getDisplayMetrics().density;
        return dp * scale + 0.5f;
    }

    /**
     * 获取屏幕基因子，可提供屏幕适配使用
     * @param context
     * @return
     */
    public static int getRadix(Context context){
       int height =  context.getResources().getDisplayMetrics().heightPixels;
       int dpi = 320;
       return height/dpi==0?1:height/dpi;
    }


}
